home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DELPHI32 / GRIDS / SPREAD32 / UNIT1.PAS < prev   
Pascal/Delphi Source File  |  1996-08-15  |  10KB  |  304 lines

  1. unit Unit1;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, Grids, spread, ExtCtrls, Menus, StdCtrls, Spin;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Spread1: TSpread;
  12.     MainMenu1: TMainMenu;
  13.     File1: TMenuItem;
  14.     Exit1: TMenuItem;
  15.     Panel1: TPanel;
  16.     Label1: TLabel;
  17.     ComboBox1: TComboBox;
  18.     Label2: TLabel;
  19.     ColorDialog1: TColorDialog;
  20.     FontDialog1: TFontDialog;
  21.     OpenDialog1: TOpenDialog;
  22.     Button1: TButton;
  23.     Bevel1: TBevel;
  24.     Label3: TLabel;
  25.     RadioButton1: TRadioButton;
  26.     RadioButton2: TRadioButton;
  27.     RadioButton3: TRadioButton;
  28.     Label4: TLabel;
  29.     SpinEdit1: TSpinEdit;
  30.     Label5: TLabel;
  31.     ComboBox2: TComboBox;
  32.     Label6: TLabel;
  33.     ComboBox3: TComboBox;
  34.     Button2: TButton;
  35.     procedure Exit1Click(Sender: TObject);
  36.     procedure Spread1Click(Sender: TObject);
  37.     procedure Button1Click(Sender: TObject);
  38.     procedure FormCreate(Sender: TObject);
  39.     procedure SetColumnHeaders;
  40.     procedure SetRowHeaders;
  41.     procedure Spread1CellTypeViol(icol, irow: Longint; Celltype,
  42.       CellEntrytype: Tctype; cellstring: String;
  43.       var NewCellstring: OpenString; var changecelltype: Boolean);
  44.     procedure Button2Click(Sender: TObject);
  45.   private
  46.     { Private declarations }
  47.   public
  48.     { Public declarations }
  49.   end;
  50.  
  51. var
  52.   Form1: TForm1;
  53.  
  54. implementation
  55.  
  56. {$R *.DFM}
  57.  
  58. procedure TForm1.Exit1Click(Sender: TObject);
  59. begin
  60.      Application.Terminate;
  61. end;
  62.  
  63. procedure TForm1.Spread1Click(Sender: TObject);
  64. var
  65.    T : Tctype;
  66. begin
  67.      label2.caption := 'Col = '+inttostr(spread1.col)+ ' Row = '+inttostr(spread1.row);
  68.      T := spread1.Getcelltype(spread1.col,spread1.row);
  69.      case T of
  70.        cttext : label2.caption := label2.caption + ' cttext';
  71.        ctformula : label2.caption := label2.caption + ' ctformula';
  72.        ctdate : label2.caption := label2.caption + ' ctdate';
  73.        cttime : label2.caption := label2.caption + ' cttime';
  74.      end;
  75. end;
  76.  
  77. procedure TForm1.Button1Click(Sender: TObject);
  78. var
  79.    Bmp : TBitmap;
  80.    Br : TBrush;
  81.    F : TFont;
  82.    Al : TAlignment;
  83.    Fmt : TFloatFormat;
  84. begin
  85.      case combobox1.itemindex of
  86.        0 :
  87.           begin
  88.             spread1.addcol;
  89.             setcolumnheaders;
  90.             setrowheaders;
  91.           end;
  92.        1 : spread1.addrow;
  93.        2 : spread1.clearbitmap(spread1.col,spread1.row);
  94.        3 :
  95.           begin
  96.            spread1.deletecol(spread1.col);
  97.            setcolumnheaders;
  98.            setrowheaders;
  99.           end;
  100.        4 : spread1.deleterow(spread1.row);
  101.        5 : spread1.hidecol(spread1.col);
  102.        6 : spread1.hiderow(spread1.row);
  103.        7 :
  104.           begin
  105.             spread1.insertcol(spread1.col);
  106.             setcolumnheaders;
  107.             setrowheaders;
  108.           end;
  109.        8 :begin
  110.             spread1.insertrow(spread1.row);
  111.             setrowheaders;
  112.           end;
  113.        9 : spread1.lockcell(spread1.col,spread1.row);
  114.        10: spread1.lockcol(spread1.col);
  115.        11: spread1.lockrow(spread1.row);
  116.        12: spread1.makebutton(spread1.col,spread1.row,'Button','');
  117.        13: spread1.makecheckbox(spread1.col,spread1.row,'Checkbox',true,'');
  118.        14:
  119.           begin
  120.             spread1.makecombobox(spread1.col,spread1.row,csdropdown,'');
  121.             spread1.addtocombo(spread1.col,spread1.row,'One');
  122.             spread1.addtocombo(spread1.col,spread1.row,'Two');
  123.             spread1.addtocombo(spread1.col,spread1.row,'Three');
  124.             spread1.addtocombo(spread1.col,spread1.row,'Four');
  125.             spread1.addtocombo(spread1.col,spread1.row,'Five');
  126.             spread1.addtocombo(spread1.col,spread1.row,'Six');
  127.             spread1.addtocombo(spread1.col,spread1.row,'Seven');
  128.             spread1.addtocombo(spread1.col,spread1.row,'Eight');
  129.             spread1.addtocombo(spread1.col,spread1.row,'Nine');
  130.             spread1.addtocombo(spread1.col,spread1.row,'Ten');
  131.           end;
  132.        15: spread1.makenewsheet;
  133.        16: spread1.makespinedit(spread1.col,spread1.row,0,'');
  134.        17:begin
  135.            if opendialog1.execute then
  136.            begin
  137.              Bmp := TBitmap.create;
  138.              Bmp.Loadfromfile(opendialog1.filename);
  139.              spread1.putbitmap(spread1.col,spread1.row,Bmp);
  140.              Bmp.free;
  141.            end;
  142.           end;
  143.        18:begin
  144.             if colordialog1.execute then
  145.             begin
  146.               Br := TBrush.Create;
  147.               Br.color := colordialog1.color;
  148.               spread1.setcellbrush(spread1.col,spread1.row,Br);
  149.               Br.Free;
  150.             end;
  151.           end;
  152.        19:begin
  153.             if colordialog1.execute then
  154.             begin
  155.               Br := TBrush.Create;
  156.               Br.color := colordialog1.color;
  157.               spread1.setcolbrush(spread1.col,Br);
  158.               Br.Free;
  159.             end;
  160.           end;
  161.        20:begin
  162.             if colordialog1.execute then
  163.             begin
  164.               Br := TBrush.Create;
  165.               Br.color := colordialog1.color;
  166.               spread1.setrowbrush(spread1.row,Br);
  167.               Br.Free;
  168.             end;
  169.           end;
  170.        21:begin
  171.             if fontdialog1.execute then
  172.             begin
  173.               F := TFont.create;
  174.               F.Assign(fontdialog1.font);
  175.               spread1.setcellfont(spread1.col,spread1.row,F);
  176.               F.Free;
  177.             end;
  178.           end;
  179.        22:begin
  180.             if fontdialog1.execute then
  181.             begin
  182.               F := TFont.create;
  183.               F.Assign(fontdialog1.font);
  184.               spread1.setcolfont(spread1.col,F);
  185.               F.Free;
  186.             end;
  187.           end;
  188.        23:begin
  189.             if fontdialog1.execute then
  190.             begin
  191.               F := TFont.create;
  192.               F.Assign(fontdialog1.font);
  193.               spread1.setrowfont(spread1.row,F);
  194.               F.Free;
  195.             end;
  196.           end;
  197.        24,25,26:begin
  198.            if radiobutton1.checked then
  199.              Al := taLeftJustify
  200.            else if radiobutton2.checked then
  201.              Al := taRightJustify
  202.            else
  203.              Al := taCenter;
  204.            if combobox1.itemindex = 24 then
  205.              spread1.setcellalignment(spread1.col,spread1.row,Al)
  206.            else if combobox1.itemindex = 25 then
  207.              spread1.setcolalignment(spread1.col,Al)
  208.            else
  209.              spread1.setrowalignment(spread1.row,Al);
  210.           end;
  211.        27,28,29: (* set cell col or row format *)
  212.           begin
  213.             case combobox2.itemindex of
  214.               0 : Fmt := ffCurrency;
  215.               1 : Fmt := ffNumber;
  216.               2 : Fmt := ffFixed;
  217.               3 : Fmt := ffGeneral;
  218.               4 : Fmt := ffExponent;
  219.             end;
  220.  
  221.             if combobox1.itemindex = 27 then
  222.               spread1.setcellformat(spread1.col,spread1.row,Fmt,spinedit1.value)
  223.             else if combobox1.itemindex = 28 then
  224.               spread1.setcolformat(spread1.col,Fmt,spinedit1.value)
  225.             else
  226.               spread1.setrowformat(spread1.row,Fmt,spinedit1.value);
  227.  
  228.           end;
  229.         30 : (* set cell type*)
  230.           begin
  231.             case combobox3.itemindex of
  232.               0 : spread1.setcelltype(spread1.col,spread1.row,cttext);
  233.               1 : spread1.setcelltype(spread1.col,spread1.row,ctformula);
  234.               2 : spread1.setcelltype(spread1.col,spread1.row,ctdate);
  235.               3 : spread1.setcelltype(spread1.col,spread1.row,cttime);
  236.             end;
  237.           end;
  238.         31 : spread1.unlockallcells;
  239.      end;
  240. end;
  241.  
  242. procedure TForm1.FormCreate(Sender: TObject);
  243. begin
  244.      SetColumnHeaders;
  245.      setrowheaders;
  246. end;
  247. procedure TForm1.SetColumnHeaders;
  248. var
  249.    i : integer;
  250. begin
  251.      for i := 0 to spread1.colcount - 1 do
  252.        spread1.cells[i,0] :=inttostr(i);
  253. end;
  254. procedure TForm1.SetRowHeaders;
  255. var
  256.    i : integer;
  257. begin
  258.      for i := 0 to spread1.rowcount - 1 do
  259.        spread1.cells[0,i] :=inttostr(i);
  260. end;
  261.  
  262. procedure TForm1.Spread1CellTypeViol(icol, irow: Longint; Celltype,
  263.   CellEntrytype: Tctype; cellstring: String; var NewCellstring: OpenString;
  264.   var changecelltype: Boolean);
  265. begin
  266.      changecelltype := true;
  267.      (* setting changecelltype to true prevents
  268.         TSpread from generating an error message
  269.         when the user types text in a cell which cannot
  270.         be evaluated as a formula.  If changecelltype
  271.         is not set to true then an error message and
  272.         the error event handler is fired.
  273.         Note that the celltype is ctformula but
  274.         after this event TSpread changes the type
  275.         to cttext since the entry can't be evaluated
  276.         as a formula.
  277.      *)
  278. end;
  279.  
  280. procedure TForm1.Button2Click(Sender: TObject);
  281. var
  282.    i : integer;
  283. begin
  284.      for i := 1 to 10 do
  285.      begin
  286.        spread1.setcelltype(1,i,ctformula);
  287.        spread1.setformula(1,i,inttostr(i));
  288.      end;
  289.      spread1.setcolalignment(1,taRightJustify);
  290.      spread1.setcelltype(1,11,ctformula);
  291.      spread1.setformula(1,11,'=a1+a2+a3+a4+a5+a6+a7+a8+a9+a10');
  292.      for i := 1 to 10 do
  293.      begin
  294.        spread1.setcelltype(2,i,ctformula);
  295.        spread1.setformula(2,i,'=a'+inttostr(i));
  296.      end;
  297.      spread1.setcolalignment(2,taRightJustify);
  298.      spread1.setcelltype(2,11,ctformula);
  299.      spread1.setformula(2,11,'=b1+b2+b3+b4+b5+b6+b7+b8+b9+b10');
  300.  
  301. end;
  302.  
  303. end.
  304.